import request from '@/utils/request'
import Qs from 'qs'

/**
 * 查询所有经销商信息
 * @param {*} params
 */
export function dealerQuery(params, data) {
  return request.get(`/platform/dealer/query?${Qs.stringify(params)}`, data)
}

/**
 *新建经销商
 *
 * @export
 * @param {*} data
 * @returns
 */
export function dealerAdd(data) {
  return request.post(`/platform/dealer`, data)
}

/**
 * 修改经销商
 *
 * @export
 * @param {*} data
 * @returns
 */
export function dealerEdit(data) {
  return request.patch(`/platform/dealer/${data.id}`, data)
}

/**
 * 删除经销商
 *
 * @export
 * @param {*} id
 * @returns
 */
export function delDealer(id) {
  return request.delete(`/platform/dealer/${id}`) 
}

/**
 * 重置密码
 *
 * @export
 * @param {*} id
 * @returns
 */
export function resetPasswordDealer(id) {
  return request.patch(`/platform/dealer/${id}/password/reset`)
}

/**
 * 经销商明细信息
 *
 * @export
 * @param {*} id
 */
export function dealerProfile(id) {
  return request.get(`/platform/dealer/${id}/profile`)
}

/**
 * 判断手机号是否存在
 *
 * @export
 * @param {*} phone
 */
export function dealerCheckPhone(phone) {
  return request.get(`/platform/dealer/phone/check?phone=${phone}`)
}

/**
 * 成员列表信息
 *
 * @export
 * @param {*} name
 * @returns
 */
export function dealePartnersQuery(dealerId, params) {
  return request.get(`/platform/dealer/${dealerId}/partners/query`, { params })
}

/**
 * 暂停成员
 *
 * @export
 * @param {*} id
 * @returns
 */
export function partnerPause(id) {
  return request.patch(`/platform/dealer/partner/${id}/_pause`)
}

/**
 * 成员基本信息
 *
 * @export
 * @param {*} id
 * @returns
 */
export function partnerProfile(dealerId) {
  return request.get(`/platform/dealer/partner/${dealerId}/info`)
}

/**
 * 查询经销商产品
 *
 * @export
 * @param {*} params
 * @returns
 */
export function productsQuery(dealerId, params) {
  return request.get(`/platform/dealer/partner/${dealerId}/products`, {params})
}

/**
 * 根据起止时间和状态搜索佣金记录
 *
 */
export function commissionRecordQuery(dealerId, params) {
  return request.get(`/platform/dealer/${dealerId}/commission/query`, {params})
}

/**
 * 提现记录
 *
 * @export
 * @param {*} data
 * @returns
 */
export function withdrawRecordQuery(dealerId, params) {
  return request.get(`/platform/dealer/${dealerId}/withdraw/query`, {params})
}

export const uploadDealerUrl = '/platform/dealer/icon/upload';